﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace XNOgre.Core
{
    public class Billboard
    {
        protected int texCoordIndex;
        protected Vector4 texCoordRect;
        protected bool ownDimensions;
        protected Vector2 size;
        protected Vector3 position, direction;
        protected BillboardSet parentSet;
        protected float rotation;
        protected Color color;
        protected bool useTexCoordRect;

        internal Billboard()
        {
            this.ownDimensions = false;
            this.TexCoordIndex = 0;
            this.position = Vector3.Zero;
            this.direction = Vector3.Zero;
            this.parentSet = null;
            this.color = Color.White;
            this.rotation = 0;
            this.texCoordIndex = 0;
            this.useTexCoordRect = false;
        }
        internal Billboard(Vector3 position, BillboardSet owner, Color color)
        {
            this.ownDimensions = false;
            this.position = position;
            this.direction = Vector3.Zero;
            this.parentSet = owner;
            this.color = color;
            this.rotation = 0;
            this.useTexCoordRect = false;
            this.texCoordIndex = 0;
            this.size = owner.DefaultDimensions;
        }

        internal void NotifyOwner(BillboardSet parent)
        {
            this.parentSet = parent;
            this.size = parent.DefaultDimensions;
        }
        public float Rotation
        {
            get { return rotation; }
            set
            {
                if (value != 0)
                {
                    parentSet.NotifyBillboardRotated();
                }
                rotation = value;
            }
        }
        public Vector3 Position
        {
            get { return position; }
            set { position = value; }
        }
        public Vector3 Direction
        {
            get;
            set;
        }
        public int TexCoordIndex
        {
            get { return texCoordIndex; }
            set
            {
                texCoordIndex = value;
                useTexCoordRect = false;
            }
        }
        public Vector4 TexCoordRect
        {
            get { return texCoordRect; }
            set
            {
                texCoordRect = value;
                useTexCoordRect = true;
            }
        }
        public Vector2 Dimensions
        {
            get { return size; }
            set 
            {
                if (size != value)
                {
                    this.ownDimensions = true;
                    parentSet.NotifyBillboardResized();
                }
                size = value; 
            }
        }
        public Color Color
        {
            get { return color; }
            set { color = value; }
        }

        public bool HasOwnDimensions
        {
            get { return ownDimensions; }
        }
        public bool UseTexCoordRect
        {
            get { return useTexCoordRect; }
        }
        public void ResetDimensions()
        {
            ownDimensions = false;
        }
    }
}
